<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>文章详情修改</title>
    <link href="${ctx }/css/style.css" rel="stylesheet" type="text/css" />
    <link rel="stylesheet" type="text/css" href="${ctx}/js/ueditor/formdesign/bootstrap/css/bootstrap.css">
    <!--[if lte IE 6]>
    <link rel="stylesheet" type="text/css" href="${ctx}/js/ueditor/formdesign/bootstrap/css/bootstrap-ie6.css">
    <![endif]-->
    <!--[if lte IE 7]>
    <link rel="stylesheet" type="text/css" href="${ctx}/js/ueditor/formdesign/bootstrap/css/ie.css">
    <![endif]-->
    <link rel="stylesheet" href="${ctx }/js/niceValidator/jquery.validator.css" />
    <script type="text/javascript" src="${ctx }/js/jquery/jquery-1.8.2.min.js"></script>
    <script type="text/javascript" src="${ctx }/js/layer/layer.js"></script>
    <script type="text/javascript" src="${ctx }/js/niceValidator/jquery.validator.js"></script>
    <script type="text/javascript" src="${ctx }/js/niceValidator/local/zh_CN.js"></script>
    <script type="text/javascript" src="${ctx }/js/common.js"></script>
</head>
<body>
<div class="listNavTitle">
    <p>
        <label style="display: inline-block">文章管理管理 ></label>
        <label style="display: inline-block">修改文章详情</label>
    </p>
</div>
<div class="formbody">
  <div class="formtitle"><span>修改文章详情</span></div>
    <form method="post" id="saveform" name="saveform">
        <textarea  name="formContent" id="leipi_parse_form" style="display:none;"></textarea>
  <input type="hidden" name="id" value="${articleContent.id}" id="articleContentId"/>
  <ul class="forminfo">
      <li>
          <label>文章编号</label>
          <input name="title" id="articleNo" value="${articleContent.articleNo}" id="articleNo" type="text" class="dfinput"  readonly="readonly"/>
      </li>
	 <li>
      <label>文章类型</label>
      <input id="typeName" value="${articleContent.typeName}" type="text" class="dfinput" placeholder="---请单击选择文章类别---" readonly="readonly"/>
      <input name="typeId" value="${articleContent.typeId}" type="hidden" class="dfinput"  />
   	 </li>
	 <li>
      <label>标题</label>
      <input name="title" id="articleTitle" value="${articleContent.title}" id="articleTitle" type="text" class="dfinput"  data-rule="标题:required;"/>
   	 </li>
	 <li>
      <label>简介</label>
      <input name="briefs" id="articleBriefs" value="${articleContent.briefs}" id="articleBriefs" type="text" class="dfinput"  data-rule="简介:required;"/>
   	 </li>
	 <li>
      <label style="align-content: center">详情描述</label>
   	 </li>
<#--	 <li>
      <label></label>
      <input name="organsPersonId" value="${articleContent.organsPersonId}" type="text" class="dfinput"  data-rule=":required;"/>
   	 </li>-->
      <li>
          <div>
              <input type="hidden" name="fields" id="fields" value="0">
              <#--<div class="well">
                  <p>
                      <button type="button" onclick="leipiFormDesign.exec('text');" class="btn-info btn-small">单行输入框</button>
                      <button type="button" onclick="leipiFormDesign.exec('textarea');" class="btn-info btn-small">多行输入框</button>
                      <button type="button" onclick="leipiFormDesign.exec('select');" class="btn-info btn-small">下拉菜单</button>
                      <button type="button" onclick="leipiFormDesign.exec('radios');" class="btn-info btn-small">单选框</button>
                      <button type="button" onclick="leipiFormDesign.exec('checkboxs');" class="btn-info btn-small">复选框</button>
                  &lt;#&ndash;<button type="button" onclick="leipiFormDesign.exec('macros');" class="btn-info btn-small">宏控件</button>&ndash;&gt;
                      <button type="button" onclick="leipiFormDesign.exec('progressbar');" class="btn-info btn-small">进度条</button>
                  &lt;#&ndash;<button type="button" onclick="leipiFormDesign.exec('qrcode');" class="btn-info btn-small">二维码</button>&ndash;&gt;
                      <button type="button" onclick="leipiFormDesign.exec('listctrl');" class="btn-info btn-small">列表控件</button>
                  </p>
              </div>-->
              <script id="myFormDesign" type="text/plain" style="width:100%;height:500px;">
                        ${articleContent.descs}
                    </script>
          </div>
      </li>
    <li>
      <label>&nbsp;</label>
        <button class="layui-btn layui-btn-normal btn" type="button" onclick="leipiFormDesign.fnCheckForm('save');" >确认保存</button>
        <#--<button class="layui-btn layui-btn-normal" type="button" class="btn" id="submitBtn">确认保存</button>-->

    </li>
  </ul>
</form>
</div>
</body>
</html>
<script type="text/javascript" src="${ctx}/js/jquery/jquery-1.7.2.min.js"></script>
<script type="text/javascript" charset="utf-8" src="${ctx}/js/ueditor/ueditor.config.js"></script>
<script type="text/javascript" charset="utf-8" src="${ctx}/js/ueditor/ueditor.all.js"> </script>
<!--建议手动加在语言，避免在ie下有时因为加载语言失败导致编辑器加载失败-->
<!--这里加载的语言文件会覆盖你在配置项目里添加的语言类型，比如你在配置项目里配置的是英文，这里加载的中文，那最后就是中文-->
<script type="text/javascript" charset="utf-8" src="${ctx}/js/ueditor/lang/zh-cn/zh-cn.js"></script>
<script type="text/javascript" charset="utf-8" src="${ctx}/js/ueditor/formdesign/leipi.formdesign.v4.js"></script>
<script>

    var leipiEditor = UE.getEditor('myFormDesign',{
        //allowDivTransToP: false,//阻止转换div 为p
        toolleipi:true,//是否显示，设计器的 toolbars
        textarea: 'design_content',
        //这里可以选择自己需要的工具按钮名称,此处仅选择如下五个
        toolbars:[[
//            'fullscreen', 'source', '|', 'undo', 'redo', '|','bold', 'italic', 'underline', 'fontborder', 'strikethrough',  'removeformat', '|', 'forecolor', 'backcolor', 'insertorderedlist', 'insertunorderedlist','|', 'fontfamily', 'fontsize', '|', 'indent', '|', 'justifyleft', 'justifycenter', 'justifyright', 'justifyjustify', '|',  'link', 'unlink',  '|',  'horizontal',  'spechars',  'wordimage', '|', 'inserttable', 'deletetable',  'mergecells',  'splittocells']],
            'fullscreen', 'source', '|', 'undo', 'redo', '|',
            'bold', 'italic', 'underline', 'fontborder', 'strikethrough', 'superscript', 'subscript', 'removeformat', 'formatmatch', 'autotypeset', 'blockquote', 'pasteplain', '|', 'forecolor', 'backcolor', 'insertorderedlist', 'insertunorderedlist', 'selectall', 'cleardoc', '|',
            'rowspacingtop', 'rowspacingbottom', 'lineheight', '|',
            'customstyle', 'paragraph', 'fontfamily', 'fontsize', '|',
            'directionalityltr', 'directionalityrtl', 'indent', '|',
            'justifyleft', 'justifycenter', 'justifyright', 'justifyjustify', '|', 'touppercase', 'tolowercase', '|',
            'link', 'unlink', 'anchor', '|', 'imagenone', 'imageleft', 'imageright', 'imagecenter', '|',
            'simpleupload', 'insertimage', 'emotion', 'scrawl', 'insertvideo', 'music', 'attachment', 'map', 'gmap', 'insertframe', 'insertcode', 'webapp', 'pagebreak', 'background', '|',
            'horizontal', 'date', 'time', 'spechars', 'snapscreen', 'wordimage', '|',
            'inserttable', 'deletetable', 'insertparagraphbeforetable', 'insertrow', 'deleterow', 'insertcol', 'deletecol', 'mergecells', 'mergeright', 'mergedown', 'splittocells', 'splittorows', 'splittocols', 'charts', '|',
            'print', 'preview', 'searchreplace', 'drafts', 'help'
        ]],
        //focus时自动清空初始化时的内容
        //autoClearinitialContent:true,
        //关闭字数统计
        wordCount:false,
        //关闭elementPath
        elementPathEnabled:false,
        //默认的编辑区域高度
//        initialFrameHeight:300
        ///,iframeCssUrl:"css/bootstrap/css/bootstrap.css" //引入自身 css使编辑器兼容你网站css
        //更多其他参数，请参考ueditor.config.js中的配置项
    });

    var leipiFormDesign = {
        /*执行控件*/
        exec : function (method) {
            leipiEditor.execCommand(method);
        },
        /*
            Javascript 解析表单
            template 表单设计器里的Html内容
            fields 字段总数
        */
        parse_form:function(template,fields)
        {
            //正则  radios|checkboxs|select 匹配的边界 |--|  因为当使用 {} 时js报错
            var preg =  /(\|-<span(((?!<span).)*leipiplugins=\"(radios|checkboxs|select)\".*?)>(.*?)<\/span>-\||<(img|input|textarea|select).*?(<\/select>|<\/textarea>|\/>))/gi,preg_attr =/(\w+)=\"(.?|.+?)\"/gi,preg_group =/<input.*?\/>/gi;
            if(!fields) fields = 0;

            var template_parse = template,template_data = new Array(),add_fields=new Object(),checkboxs=0;

            var pno = 0;
            template.replace(preg, function(plugin,p1,p2,p3,p4,p5,p6){
                var parse_attr = new Array(),attr_arr_all = new Object(),name = '', select_dot = '' , is_new=false;
                var p0 = plugin;
                var tag = p6 ? p6 : p4;
                //alert(tag + " \n- t1 - "+p1 +" \n-2- " +p2+" \n-3- " +p3+" \n-4- " +p4+" \n-5- " +p5+" \n-6- " +p6);

                if(tag == 'radios' || tag == 'checkboxs')
                {
                    plugin = p2;
                }else if(tag == 'select')
                {
                    plugin = plugin.replace('|-','');
                    plugin = plugin.replace('-|','');
                }
                plugin.replace(preg_attr, function(str0,attr,val) {
                    if(attr=='name')
                    {
                        if(val=='leipiNewField')
                        {
                            var d = new Date();
                            var randomsFieLdName = d.getTime();
//                            console.log(randomsFieLdName);
                            is_new=true;
                            fields++;
                            val = 'data_'+randomsFieLdName;
                        }
                        name = val;
                    }

                    if(tag=='select' && attr=='value')
                    {
                        if(!attr_arr_all[attr]) attr_arr_all[attr] = '';
                        attr_arr_all[attr] += select_dot + val;
                        select_dot = ',';
                    }else
                    {
                        attr_arr_all[attr] = val;
                    }
                    var oField = new Object();
                    oField[attr] = val;
                    parse_attr.push(oField);
                })
                /*alert(JSON.stringify(parse_attr));return;*/
                if(tag =='checkboxs') /*复选组  多个字段 */
                {
                    plugin = p0;
                    plugin = plugin.replace('|-','');
                    plugin = plugin.replace('-|','');
                    var name = 'checkboxs_'+checkboxs;
                    attr_arr_all['parse_name'] = name;
                    attr_arr_all['name'] = '';
                    attr_arr_all['value'] = '';

//                    console.log(attr_arr_all);
                    attr_arr_all['content'] = '<span leipiplugins="checkboxs"  title="'+attr_arr_all['title']+'" ';//'>';
                    if (attr_arr_all['orgnames']) {
                        attr_arr_all['content'] += 'orgnames="'+attr_arr_all['orgnames']+'" ';
                    }
                    if (attr_arr_all['orgreadonly']) {
                        attr_arr_all['content'] += 'orgreadonly="'+attr_arr_all['orgreadonly']+'" ';
                    }
                    if (attr_arr_all['orgtype']) {
                        attr_arr_all['content'] += 'orgtype="'+attr_arr_all['orgtype']+'" ';
                    }
                    attr_arr_all['content'] += '>';
                    var dot_name ='', dot_value = '';
                    p5.replace(preg_group, function(parse_group) {
                        var is_new=false,option = new Object();
                        parse_group.replace(preg_attr, function(str0,k,val) {
                            if(k=='name')
                            {
                                if(val=='leipiNewField')
                                {
                                    var d = new Date();
                                    var randomsFieLdName = d.getTime();
                                    is_new=true;
                                    fields++;
//                                    val = 'data_'+fields;
                                    val = 'data_'+randomsFieLdName;
                                }
                                //多选框使用1个name
//                                attr_arr_all['name'] += dot_name + val;
                                attr_arr_all['name'] = val;
                                dot_name = ',';

                            }
                            else if(k=='value')
                            {
                                attr_arr_all['value'] += dot_value + val;
                                dot_value = ',';

                            }
                            option[k] = val;
                        });

                        if(!attr_arr_all['options']) attr_arr_all['options'] = new Array();
                        attr_arr_all['options'].push(option);
                        //if(!option['checked']) option['checked'] = '';
                        var checked = option['checked'] !=undefined ? 'checked="checked"' : '';
                        attr_arr_all['content'] +='<input type="checkbox" name="'+attr_arr_all['name']+'" value="'+option['value']+'"  ';//checked+'/>'+option['value']+'&nbsp;';
                        if (option['orgreadonly']) {
                            attr_arr_all['content'] +='orgreadonly="'+option['orgreadonly']+'" ';
                        }
                        if (option['orgtype']) {
                            attr_arr_all['content'] += 'orgtype="'+option['orgtype']+'" ';
                        }
                        attr_arr_all['content'] +=checked+'/>'+option['value']+'&nbsp;';
                        if(is_new)
                        {
                            var arr = new Object();
                            arr['name'] = option['name'];
                            arr['leipiplugins'] = attr_arr_all['leipiplugins'];
                            add_fields[option['name']] = arr;

                        }

                    });
                    attr_arr_all['content'] += '</span>';

                    //parse
                    template = template.replace(plugin,attr_arr_all['content']);
                    template_parse = template_parse.replace(plugin,'{'+name+'}');
                    template_parse = template_parse.replace('{|-','');
                    template_parse = template_parse.replace('-|}','');
                    template_data[pno] = attr_arr_all;
                    checkboxs++;

                }else if(name)
                {
                    if(tag =='radios') /*单选组  一个字段*/
                    {
                        plugin = p0;
                        plugin = plugin.replace('|-','');
                        plugin = plugin.replace('-|','');
                        attr_arr_all['value'] = '';
                        attr_arr_all['content'] = '<span leipiplugins="radios" name="'+attr_arr_all['name']+'" title="'+attr_arr_all['title']+'" ';//>';
                        if (attr_arr_all['orgnames']) {
                            attr_arr_all['content'] += 'orgnames="'+attr_arr_all['orgnames']+'" ';
                        }
                        if (attr_arr_all['orgreadonly']) {
                            attr_arr_all['content'] += 'orgreadonly="'+attr_arr_all['orgreadonly']+'" ';
                        }
                        if (attr_arr_all['orgtype']) {
                            attr_arr_all['content'] += 'orgtype="'+attr_arr_all['orgtype']+'" ';
                        }
                        attr_arr_all['content'] += '>';
                        var dot='';
                        p5.replace(preg_group, function(parse_group) {
                            var option = new Object();
                            parse_group.replace(preg_attr, function(str0,k,val) {
                                if(k=='value')
                                {
                                    attr_arr_all['value'] += dot + val;
                                    dot = ',';
                                }
                                option[k] = val;
                            });
                            option['name'] = attr_arr_all['name'];
                            if(!attr_arr_all['options']) attr_arr_all['options'] = new Array();
                            attr_arr_all['options'].push(option);
                            //if(!option['checked']) option['checked'] = '';
                            var checked = option['checked'] !=undefined ? 'checked="checked"' : '';
                            attr_arr_all['content'] +='<input type="radio" name="'+attr_arr_all['name']+'" value="'+option['value']+'"  ';//'" '+checked+'/>'+option['value']+'&nbsp;';
                            if (option['orgreadonly']) {
                                attr_arr_all['content'] +='orgreadonly="'+option['orgreadonly']+'" ';
                            }
                            if (option['orgtype']) {
                                attr_arr_all['content'] += 'orgtype="'+option['orgtype']+'" ';
                            }
                            attr_arr_all['content'] +=checked+'/>'+option['value']+'&nbsp;';
                        });
                        attr_arr_all['content'] += '</span>';

                    }else
                    {
                        attr_arr_all['content'] = is_new ? plugin.replace(/leipiNewField/,name) : plugin;
                    }
                    //attr_arr_all['itemid'] = fields;
                    //attr_arr_all['tag'] = tag;
                    template = template.replace(plugin,attr_arr_all['content']);
                    template_parse = template_parse.replace(plugin,'{'+name+'}');
                    template_parse = template_parse.replace('{|-','');
                    template_parse = template_parse.replace('-|}','');
                    if(is_new)
                    {
                        var arr = new Object();
                        arr['name'] = name;
                        arr['leipiplugins'] = attr_arr_all['leipiplugins'];
                        add_fields[arr['name']] = arr;
                    }
                    template_data[pno] = attr_arr_all;


                }
                pno++;
            })
            var parse_form = new Object({
                'fields':fields,//总字段数
                'template':template,//完整html
                'parse':template_parse,//控件替换为{data_1}的html
                'data':template_data,//控件属性
                'add_fields':add_fields//新增控件
            });
            return JSON.stringify(parse_form);
        },
        /*type  =  save 保存设计 versions 保存版本  close关闭 */
        fnCheckForm : function ( type ) {
            if(leipiEditor.queryCommandState( 'source' ))
                leipiEditor.execCommand('source');//切换到编辑模式才提交，否则有bug

            var articleTitle=$("#articleTitle").val(),articleBriefs=$("#articleBriefs").val(),typeName=$("#typeName").val();

            if (typeName==null||typeName=="") {
                layer.alert('请选择文章类别！');
                return false;
            }

            if (articleTitle==null||articleTitle=="") {
                layer.alert('标题不能为空！');
                return false;
            }

            if (articleBriefs==null||articleBriefs=="") {
                layer.alert('简介不能为空！');
                return false;
            }

            if(leipiEditor.hasContents()){
                leipiEditor.sync();/*同步内容*/

//                alert("你点击了保存,这里可以异步提交，请自行处理....");
//                return false;
                //--------------以下仅参考-----------------------------------------------------------------------------------------------------
                var type_value='',formid=0,fields=$("#fields").val(),formeditor='',typeId=$("#typeId").val(),articleContentId=$("#articleContentId").val();

                if( typeof type!=='undefined' ){
                    type_value = type;
                }
                //获取表单设计器里的内容
                formeditor=leipiEditor.getContent();
                //解析表单设计器控件
                var parse_form = this.parse_form(formeditor,fields);
//                alert(parse_form);
                var index = parent.layer.getFrameIndex(window.name);
                //异步提交数据
                $.ajax({
                    type: 'POST',
                    url : '${ctx }/sysman/helpme/upChange.do',
                    //dataType : 'json',
                    data: {
                        'id': articleContentId,
                        'type': type_value,
                        'title': articleTitle,
                        'descs': parse_form,
                        'typeId': typeId,
                        'formid': formid,
                        'briefs': articleBriefs,
                    },
                    success : function(data){
                        /*if(confirm('查看js解析后，提交到服务器的数据，请临时允许弹窗'))
                        {
                            win_parse=window.open('','','width=800,height=600');
                            //这里临时查看，所以替换一下，实际情况下不需要替换
                            data  = data.replace(/<\/+textarea/,'&lt;textarea');
                            win_parse.document.write('<textarea style="width:100%;height:100%">'+data+'</textarea>');
                            win_parse.focus();
                        }
*/
                        if(data.status=="SUCCESS"){
                            window.parent.baseSearchQueryLayer('Refresh','Refresh');
                            window.parent.baseBottomMsgOpen('修改成功');
                            window.parent.layer.close(index);
//                            alert('保存成功');
//                            $('#submitbtn').button('reset');
                        }else{
                            layer.alert(data.msg);
                        }
                    }
                });

            } else {
                layer.alert('表单内容不能为空！');
//                $('#submitbtn').button('reset');
                return false;
            }
        } ,
        /*预览表单*/
        fnReview : function (){
            if(leipiEditor.queryCommandState( 'source' ))
                leipiEditor.execCommand('source');/*切换到编辑模式才提交，否则部分浏览器有bug*/

            if(leipiEditor.hasContents()){
                leipiEditor.sync();       /*同步内容*/

//                alert("你点击了预览,请自行处理....");
//                return false;
                //--------------以下仅参考-------------------------------------------------------------------


                /*设计form的target 然后提交至一个新的窗口进行预览*/
                var fields=$("#fields").val();
                //获取表单设计器里的内容
                formeditor=leipiEditor.getContent();
                var parse_form = this.parse_form(formeditor,fields);
//                console.log(parse_form);
                /*设计form的target 然后提交至一个新的窗口进行预览*/
                document.saveform.target="mywin";
                window.open('','mywin',"menubar=0,toolbar=0,status=0,resizable=1,left=0,top=0,scrollbars=1,width=" +(screen.availWidth-10) + ",height=" + (screen.availHeight-50) + "\"");
                $("#leipi_parse_form").val(parse_form);

                $("#saveform").attr("action","${ctx }/sysman/helpme/preview.do");
                $("#saveform").submit();
            } else {
                alert('表单内容不能为空！');
                return false;
            }
        }
    };
    $(document).ready(function(){

        $("#typeName").click(function () {
            //var secInspe = $(this).attr("name");
            layer.open({
                type: 2,
                title: '文章类别',
                maxmin: false,
                shadeClose: true, //点击遮罩关闭层
                area : ['315px' , '455px'],
                content: '${ctx}/sysman/articles/toArticleTypePopup.do'
            });

        });
    });
    /*$(document).ready(function(){
        $("#submitBtn").click(function(){
            baseEdit('${ctx }/articleContent/upChange.do');
        });
    });*/
</script>